#!/usr/local/bin/perl
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
# 
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
# 
# The Original Code is Komodo code.
# 
# The Initial Developer of the Original Code is ActiveState Software Inc.
# Portions created by ActiveState Software Inc are Copyright (C) 2000-2007
# ActiveState Software Inc. All Rights Reserved.
# 
# Contributor(s):
#   ActiveState Software Inc
# 
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
# 
# ***** END LICENSE BLOCK *****


Import(
    "cons",
    "build",
    "mozComponentsDir",
    "mozIdlIncludePath",
    "idlExportDir",
    "ranRegxpcomStateFileName",
    "komodoPythonUtilsDir",
    'platform',
    'mozSrc',
    'mozVersion',
    'productType',
    'buildFlavour',
    'buildType',
    'unsiloedPythonExe',
    'komodoDevDir',
    'siloedPython',
    'sdkDir',
    'supportDir',
);


# src/komodo/...
$cons->Install($idlExportDir, "src/komodo/koICodeIntel.idl");
$cons->BuildAndInstallXpt("src/komodo/koICodeIntel.idl");
$cons->InstallXpcomComponent("src/komodo/koCodeIntel.py");
$cons->InstallXpcomComponent("src/komodo/koCatalogsTree.py");

$cons->BuildAndInstallXpt("src/komodo/koIScintillaAutoCompleteController.idl");
$cons->InstallXpcomComponent("src/komodo/koScintillaAutoCompleteController.js",
                             {'@activestate.com/koScintillaAutoCompleteController;1' => '{88febdcd-e6f0-4542-9d16-464413967757}'});


$cons->InstallXpcomComponent("src/komodo/koCodeIntelXPCOMSupport.py");
$cons->InstallXpcomComponent("src/komodo/xpcomJSElements.py");


my @codeintel2_files = (
    "lib/codeintel2/accessor.py",
    "lib/codeintel2/buffer.py",
    "lib/codeintel2/citadel.py",
    "lib/codeintel2/citadel_common.py",
    "lib/codeintel2/common.py",
    "lib/codeintel2/constants_css1.py",
    "lib/codeintel2/constants_css2.py",
    "lib/codeintel2/constants_css3.py",
    "lib/codeintel2/constants_css_microsoft_extensions.py",
    "lib/codeintel2/constants_css_moz_extensions.py",
    "lib/codeintel2/constants_css_webkit_extensions.py",
    "lib/codeintel2/css_linter.py",
    "lib/codeintel2/environment.py",
    "lib/codeintel2/hooks.py",
    "lib/codeintel2/indexer.py",
    "lib/codeintel2/gencix_utils.py",
    "lib/codeintel2/jsdoc.py",
    "lib/codeintel2/langintel.py",
    "lib/codeintel2/lang_css.py",
    "lib/codeintel2/lang_javascript.py",
    "lib/codeintel2/lang_less.py",
    "lib/codeintel2/lang_nodejs.py",
    "lib/codeintel2/lang_perl.py",
    "lib/codeintel2/lang_python.py",
    "lib/codeintel2/lang_python3.py",
    "lib/codeintel2/lang_ruby.py",
    "lib/codeintel2/lang_ruby_common.py",
    "lib/codeintel2/lang_tcl.py",
    "lib/codeintel2/manager.py",
    "lib/codeintel2/parser_cix.py",
    "lib/codeintel2/parser_data.py",
    "lib/codeintel2/parseutil.py",
    "lib/codeintel2/perlcile.py",
    "lib/codeintel2/perl_lexer.py",
    "lib/codeintel2/perl_parser.py",
    "lib/codeintel2/phpdoc.py",
    "lib/codeintel2/pybinary.py",
    "lib/codeintel2/pythoncile.py",
    "lib/codeintel2/pythoncile1.py",
    "lib/codeintel2/rubycile.py",
    "lib/codeintel2/ruby_lexer.py",
    "lib/codeintel2/ruby_parser.py",
    "lib/codeintel2/tclcile.py",
    "lib/codeintel2/tcl_lexer.py",
    "lib/codeintel2/tcl_parser.py",
    "lib/codeintel2/tdparser.py",
    "lib/codeintel2/tree.py",
    "lib/codeintel2/tree_javascript.py",
    "lib/codeintel2/tree_perl.py",
    "lib/codeintel2/tree_php.py",
    "lib/codeintel2/tree_python.py",
    "lib/codeintel2/tree_ruby.py",
    "lib/codeintel2/shared_lexer.py",
    "lib/codeintel2/shared_parser.py",
    "lib/codeintel2/udl.py",
    "lib/codeintel2/util.py",
    #"lib/codeintel2/xblcile.py",
    #"lib/codeintel2/xsltcile.py",
    "lib/codeintel2/__init__.py",
);
foreach my $file (@codeintel2_files) {
    $cons->InstallPythonUtility($file, "codeintel2");
}

my @pygencix_files = ("support/gencix/python/gencixcore.py",
                      "support/gencix/python/parsedocs.py");
foreach my $file (@pygencix_files) {
    $cons->InstallPythonUtility($file, "gencix/python");
}

my @codeintel2_database_files = (
    "lib/codeintel2/database/__init__.py",
    "lib/codeintel2/database/catalog.py",
    "lib/codeintel2/database/database.py",
    "lib/codeintel2/database/langlibbase.py",
    "lib/codeintel2/database/langlib.py",
    "lib/codeintel2/database/multilanglib.py",
    "lib/codeintel2/database/projlib.py",
    "lib/codeintel2/database/resource.py",
    "lib/codeintel2/database/stdlib.py",
    "lib/codeintel2/database/util.py",
);
foreach my $file (@codeintel2_database_files) {
    $cons->InstallPythonUtility($file, "codeintel2/database");
}

my @stdlibs_files = (
    "lib/codeintel2/stdlibs/javascript.cix",
    "lib/codeintel2/stdlibs/python-2.7.cix",
    "lib/codeintel2/stdlibs/python3-3.1.cix",
    "lib/codeintel2/stdlibs/python3-3.2.cix",
    "lib/codeintel2/stdlibs/python3-3.3.cix",
    "lib/codeintel2/stdlibs/python3-3.4.cix",
    "lib/codeintel2/stdlibs/python3-3.5.cix",
    "lib/codeintel2/stdlibs/perl-5.8.cix",
    "lib/codeintel2/stdlibs/perl-5.16.cix",
    "lib/codeintel2/stdlibs/perl-5.22.cix",
    "lib/codeintel2/stdlibs/ruby-1.8.cix",
    "lib/codeintel2/stdlibs/ruby-1.9.2.cix",
    "lib/codeintel2/stdlibs/ruby-1.9.3.cix",
    "lib/codeintel2/stdlibs/ruby-2.2.cix",
    "lib/codeintel2/stdlibs/ruby-2.3.cix",
    "lib/codeintel2/stdlibs/php-4.4.cix",
    "lib/codeintel2/stdlibs/php-5.2.cix",
    "lib/codeintel2/stdlibs/php-5.3.cix",
    "lib/codeintel2/stdlibs/php-5.4.cix",
    "lib/codeintel2/stdlibs/php-5.5.cix",
    "lib/codeintel2/stdlibs/php-5.6.cix",
    "lib/codeintel2/stdlibs/php-7.0.cix",
    "lib/codeintel2/stdlibs/node.js.cix",
);
foreach my $file (@stdlibs_files) {
    $cons->InstallPythonUtility($file, "codeintel2/stdlibs");
}

my @catalog_files = (
    "lib/codeintel2/catalogs/dojo.cix",
    "lib/codeintel2/catalogs/yui.cix",
    "lib/codeintel2/catalogs/mochikit.cix",
    "lib/codeintel2/catalogs/phpunit-5.cix",
    "lib/codeintel2/catalogs/smarty2.cix",
    "lib/codeintel2/catalogs/prototype.cix",
    "lib/codeintel2/catalogs/pywin32.cix",
    "lib/codeintel2/catalogs/python3-pywin32.cix",
    "lib/codeintel2/catalogs/rails.cix",
    "lib/codeintel2/catalogs/jquery.cix",
    "lib/codeintel2/catalogs/xbl.cix",
    "lib/codeintel2/catalogs/ember.cix",
    "lib/codeintel2/catalogs/angular.cix",
    #TODO: "lib/codeintel2/catalogs/pecl.cix",
    #TODO: "lib/codeintel2/catalogs/drupal.cix",
    "lib/codeintel2/catalogs/xpcom.cix",
);
foreach my $file (@catalog_files) {
    $cons->InstallPythonUtility($file, "codeintel2/catalogs");
}

my @codeintel2_oop_files = (
    # Files for out-of-process codeintel
    "lib/codeintel2/oop/__init__.py",
    "lib/codeintel2/oop/controller.py",
    "lib/codeintel2/oop/driver.py",
    "lib/codeintel2/oop/memory_reporter.py",
);

foreach my $file (@codeintel2_oop_files) {
    $cons->InstallPythonUtility($file, "codeintel2/oop");
}
$cons->Install("$supportDir/codeintel", "bin/oop-driver.py");

# Node.js standard library comes as raw JS files
# Generated by /src/codeintel/support/gencix/javascript/nodejs/node_html_to_js.py
$cons->InstallRecursive("$komodoPythonUtilsDir/codeintel2/lib_srcs/node.js",
                        cwd()."/src/codeintel/lib/codeintel2/lib_srcs/node.js");
# InstallRecursive must take absolute paths for input (bug in InstallRecursive)
# lib/codeintel2/stdlibs/node.js.cix above generated by
# /src/codeintel/support/gencix/javascript/nodejs/node_global_cix.py

# Build codeintel's custom cElementTree -> ciElementTree.
my $PYD = ($platform eq "win") ? (($buildType eq "debug") ? "_d.pyd" : ".pyd") : ".so";
my $ciElementTreeExt = "lib/ciElementTree$PYD";
$cons->Command(
    $ciElementTreeExt,
    # files needed to do the generation
    "Makefile.py",
    "config.py",
    qq(
        $unsiloedPythonExe bin/run-in-dir.py %1:d python %1:f distclean_elementtree elementtree
    )
);
$cons->DependsRecursive($ciElementTreeExt, "support",
                        ('\.consign', '.*\.pyc', 'gencix', 'cix2html\.py',
                         '\.svn'));
$cons->DependsRecursive($ciElementTreeExt, "src/patches", ('\.svn'));
#TODO: Should have the following 2 deps but they cause ciElementTree.so
#      to *always* get rebuilt.
#$cons->DependsRecursive($ciElementTreeExt, "$komodoDevDir/contrib/elementtree",
#                        ('\.svn'));
#$cons->DependsRecursive($ciElementTreeExt, "$komodoDevDir/contrib/cElementTree",
#                        ('\.svn'));

$cons->InstallPythonUtility($ciElementTreeExt);
